package functionalTest;

import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import java.io.IOException;

public class SignIn extends AutotestUtils{

    @ParameterizedTest
    @CsvFileSource(resources = "/test.csv")
    public void signTest(String username, String password) throws IOException {
        // 找到注册用户输入框
        WebElement signInput = webDriver.findElement(By.id("signUpUser"));
        signInput.sendKeys(username);

        // 找到密码输入框
        WebElement signUpPassword = webDriver.findElement(By.id("signUpPassword"));
        signUpPassword.sendKeys(password);

        // 点击注册
        WebElement button = webDriver.findElement(By.cssSelector("#signUpSubmit"));
        // 使用 JavaScript 触发点击
        JavascriptExecutor js = (JavascriptExecutor) webDriver;
        js.executeScript("arguments[0].click();", button);

        // 用注册的账户进行登录, 若登录成功说明注册成功
        LoginTest login = new LoginTest();
        login.loginTest(username, password);
    }
}
